use uuid::Uuid;

use chrono::{DateTime, Utc};

#[derive(Debug, Clone, sqlx::FromRow)]
pub struct Feed {
    pub id: Uuid,
    pub url: String,
    pub feed_type: AtomOrRss,
    pub last_update_time: DateTime<Utc>,
}
impl Feed {
    pub fn new(
        id: Uuid,
        last_update_time: DateTime<Utc>,
        url: String,
        feed_type: AtomOrRss,
    ) -> Self {
        Self {
            id,
            last_update_time,
            url,
            feed_type,
        }
    }
    pub fn last_update_time(&self) -> DateTime<Utc> {
        self.last_update_time
    }
    pub fn set_last_update_time(&mut self, last_update_time: DateTime<Utc>) {
        self.last_update_time = last_update_time;
    }
    pub fn url(&self) -> String {
        self.url.clone()
    }
    pub fn set_url(&mut self, url: String) {
        self.url = url;
    }
}
use derive_more::derive::FromStr;
//use derive_more::FromStr;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, FromStr)]
pub enum AtomOrRss {
    Atom,
    Rss,
}
// impl Encode for AtomOrRss {

// }
impl ToString for AtomOrRss {
    fn to_string(&self) -> String {
        match self {
            Self::Atom => "atom".to_string(),
            Self::Rss => "rss".to_string(),
        }
    }
}
// impl FromStr for AtomOrRss {
//     type Err = FromStr::Err;
//     fn from_str(s: &str) -> Result<Self, Self::Err> {
//         match s {
//             "atom" => Ok(Self::Atom),
//             "rss" => Ok(Self::Rss),
//             _ => Err(""),
//         }
//     }
// }
